<!DOCTYPE html>
<%@ page language="java" import="com.compuvest.web.*" pageEncoding="UTF-8" %>

<%@ taglib uri="/WEB-INF/tld/head.tld" prefix="head" %>

<jsp:useBean id="sb" class="SQLBean" scope="application"/>
<jsp:useBean id="advertShow" class="AdvertShow" scope="application"/>
<jsp:useBean id="basket" class="Basket" scope="session"/>
<%
/*
    out.println("<pre>------------------");
    java.util.Enumeration params = request.getParameterNames();
        while(params.hasMoreElements()) {
        String paramName = (String)params.nextElement();
        String[] paramValues = request.getParameterValues(paramName);
        if(paramValues.length == 1) {
	    out.print(paramName + "=[" + paramValues[0] + "]");
	}
	else {
    	    out.print(paramName + "=[" );
	    for(int i = 0; i < paramValues.length; i++) {
	        if(i > 0) out.print(",");
    		out.print(paramValues[i]);
	    }
    	    out.print("]");
	}
    	out.println();
    }
    out.println("------------------</pre>");
*/
    Customer cust = basket.getCustomer();
    if(cust == null) {
	response.sendRedirect(application.getInitParameter("https") + "CustomerForm.jsp");
	return;
    }

    String vpassword = request.getParameter("vPassword") == null ? cust.getPassword() : request.getParameter("vPassword");
    String mode = request.getParameter("mode");
    if(mode != null && mode.equals("Submit")) {

	cust.setPassword(request.getParameter("Password"));

	cust.getBilling().setCompany(request.getParameter("billingCompany"));
	cust.getBilling().setFirstName(request.getParameter("billingFirstName"));
	cust.getBilling().setLastName(request.getParameter("billingLastName"));
	cust.getBilling().setAddress1(request.getParameter("billingAddress1"));
	cust.getBilling().setAddress2(request.getParameter("billingAddress2"));
	cust.getBilling().setCity(request.getParameter("billingCity"));
	cust.getBilling().setCountry(request.getParameter("billingCountry"));
	cust.getBilling().setState(request.getParameter("billingState"));
	cust.getBilling().setZip(request.getParameter("billingZip"));
	cust.getBilling().setZip4(request.getParameter("billingZip4"));
	cust.getBilling().setPhone(request.getParameter("billingPhone"));
	cust.getBilling().setCell(request.getParameter("billingCell"));
	cust.getBilling().setFax(request.getParameter("billingFax"));

	cust.getShipping().setCompany(request.getParameter("shippingCompany"));
	cust.getShipping().setFirstName(request.getParameter("shippingFirstName"));
	cust.getShipping().setLastName(request.getParameter("shippingLastName"));
	cust.getShipping().setAddress1(request.getParameter("shippingAddress1"));
	cust.getShipping().setAddress2(request.getParameter("shippingAddress2"));
	cust.getShipping().setCity(request.getParameter("shippingCity"));
	cust.getShipping().setCountry(request.getParameter("shippingCountry"));
	cust.getShipping().setState(request.getParameter("shippingState"));
	cust.getShipping().setZip(request.getParameter("shippingZip"));
	cust.getShipping().setZip4(request.getParameter("shippingZip4"));
	cust.getShipping().setPhone(request.getParameter("shippingPhone"));
        cust.getShipping().setCell(request.getParameter("shippingCell"));
        cust.getShipping().setFax(request.getParameter("shippingFax"));

	if(cust.getCustomerID() != 0) {
            sb.updateCustomer(cust, basket.getCompuvestCookies().getIPAddress());
	}

        response.sendRedirect(application.getInitParameter("https") + "Payment.jsp");
	return;
    }
%>
<html>
<head>
<title><%= application.getInitParameter("CompanyName") %></title>
<%@include file="./incl/scripts.txt" %>
</head>
<body>

<div id='cvbody'>

 <head:show />

 <div id='cvcont'>
  <table id='cvmain'>
  <colgroup><col width='80px'/><col width='*'/><col width='80px'/></colgroup>
  <tbody>
   <tr>
    <td id='cvleft' valign="top">


    </td>
    <td id='cvcenter' align="center" valign="top">

<br/>
<form id='Customer' action='<%= application.getInitParameter("https") %>CustomerEdit.jsp' onSubmit='return isDone(this);' enctype='application/x-www-form-urlencoded' method='POST'>

<table style='width:80%'>
 <tr>
  <td>
  <table id='custform'>
  <colgroup><col width='35%'/><col width='65%'/></colgroup>
   <tr><th>Email :</th>
    <td><%= cust.getEmail() %></td>
   </tr>
   <tr><th>Password :</th>
    <td><input type='password' name='Password' size='30' maxlength='15' value='<%= cust.getPassword() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Confirm Password :</th>
    <td><input type='password' name='vPassword' size='30' maxlength='15' value='<%= vpassword %>' onchange='checkPassword();'/></td>
   </tr>
<%    if("R".equals(cust.getType())) { %>
   <tr><th>Reseller Certificate #</th><td><%= cust.getResellerCode() %></td></tr>
<%    } %>
  </table>
  </td>
  <td colspan='2'>&nbsp;</td>
 </tr>

 <tr><td colspan='3'>&nbsp;</td></tr>
 <tr align='center'>
  <td width='43%' class='bsm'><b>Billing Address</b></td><td width='14%'>&nbsp;</td><td width='43%' class='bsm'><b>Shipping Address</b></td>
 </tr>
 <tr class='messg'>
  <td><font color='red'>Note:</font> Your Billing address (address where credit card bank statement goes to) has to be entered with high accuracy.
   We use it to verify credit card information. If information is incorrect or incomplete, your order will not be shipped.
  </td>
  <td>&nbsp;</td>
  <td><font color='red'>Note: </font>If shipping information is different than billing information and you are paying
   by credit/debit card, your order may be delayed for verification.
  </td>
 </tr>


 <tr valign='top'>
  <td>
  <table id='custform'>
  <colgroup><col width='35%'/><col width='65%'/></colgroup>
   <tr><th>Company Name :</th>
    <td><input type='text' name='billingCompany' size='30' maxlength='40' value='<%= cust.getBilling().getCompany() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>First Name :</th>
    <td><input type='text' name='billingFirstName' size='30' maxlength='25' value='<%= cust.getBilling().getFirstName() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Last Name :</th>
    <td><input type='text' name='billingLastName' size='30' maxlength='25' value='<%= cust.getBilling().getLastName() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Address1 :</th>
    <td><input type='text' name='billingAddress1' size='30' maxlength='40' value='<%= cust.getBilling().getAddress1() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Address2 :</th>
    <td><input type='text' name='billingAddress2' size='30' maxlength='40' value='<%= cust.getBilling().getAddress2() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Country :</th>
    <td>
    <select name='billingCountry' style='width:205px;'>
    <%= advertShow.getCountryList(cust.getBilling().getCountry()) %>
    </select>
    </td>
   </tr>
   <tr><th>City/Locality :</th>
    <td><input type='text' name='billingCity' size='30' maxlength='30' value='<%= cust.getBilling().getCity() %>'/></td>
   </tr>
   <tr><th>State :</th>
    <td>
    <select name='billingState' style='width:205px;'>
     <option value=''/>
    <%= advertShow.getAllStateList(cust.getBilling().getState()) %>
    </select>
    </td>
   </tr>
   <tr><th>Postal/Zip Code :</th>
    <td>
     <input type='text' name='billingZip' size='10' maxlength='10' value='<%= cust.getBilling().getZip() %>' onChange='this.value=toAlphaNumeric(this.value);'/> <b>-</b>
     <input type='text' name='billingZip4' size='4' maxlength='4' value='<%= cust.getBilling().getZip4() %>' onChange='this.value=toAlphaNumeric(this.value);'/>
    </td>
   </tr>
   <tr><th>Phone :</th>
    <td><input type='text' name='billingPhone' size='30' maxlength='20' value='<%= cust.getBilling().getPhone() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Cell :</th>
    <td><input type='text' name='billingCell' size='30' maxlength='20' value='<%= cust.getBilling().getCell() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Fax :</th>
    <td><input type='text' name='billingFax' size='30' maxlength='20' value='<%= cust.getBilling().getFax() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
  </table>
  </td>

  <td align='center' valign='middle'><button onClick='copyBillToShipp();return false;'>Shipping as Billing</button></td>

  <td>
  <table id='custform'>
  <colgroup><col width='35%'/><col width='65%'/></colgroup>
   <tr><th>Company Name :</th>
    <td><input type='text' name='shippingCompany' size='30' maxlength='40' value='<%= cust.getShipping().getCompany() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>First Name :</th>
    <td><input type='text' name='shippingFirstName' size='30' maxlength='25' value='<%= cust.getShipping().getFirstName() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Last Name :</th>
    <td><input type='text' name='shippingLastName' size='30' maxlength='25' value='<%= cust.getShipping().getLastName() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Address1 :</th>
    <td><input type='text' name='shippingAddress1' size='30' maxlength='40' value='<%= cust.getShipping().getAddress1() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Address2 :</th>
    <td><input type='text' name='shippingAddress2' size='30' maxlength='40' value='<%= cust.getShipping().getAddress2() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Country :</th>
    <td>
    <select name='shippingCountry' style='width:205px;'>
    <%= advertShow.getCountryList(cust.getShipping().getCountry()) %>
    </select>
    </td>
   </tr>
   <tr><th>City/Locality :</th>
    <td><input type='text' name='shippingCity' size='30' maxlength='30' value='<%= cust.getShipping().getCity() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>State :</th>
    <td>
    <select name='shippingState' style='width:205px;'>
     <option value=''/>
    <%= advertShow.getAllStateList(cust.getShipping().getState()) %>
    </select>
    </td>
   </tr>
   <tr><th>Postal/Zip Code :</th>
    <td>
     <input type='text' name='shippingZip' size='10' maxlength='10' value='<%= cust.getShipping().getZip() %>' onChange='this.value=toAlphaNumeric(this.value);'/> <b>-</b>
     <input type='text' name='shippingZip4' size='4' maxlength='4' value='<%= cust.getShipping().getZip4() %>' onChange='this.value=toAlphaNumeric(this.value);'/>
    </td>
   </tr>
   <tr><th>Phone :</th>
    <td><input type='text' name='shippingPhone' size='30' maxlength='20' value='<%= cust.getShipping().getPhone() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Cell :</th>
    <td><input type='text' name='shippingCell' size='30' maxlength='20' value='<%= cust.getShipping().getCell() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
   <tr><th>Fax :</th>
    <td><input type='text' name='shippingFax' size='30' maxlength='20' value='<%= cust.getShipping().getFax() %>' onChange='this.value=toAlphaNumeric(this.value);'/></td>
   </tr>
  </table>
  </td>

 </tr>
</table>

<br/>
<hr width='90%'/>
<br/>
<input type='submit' name='mode' value='Submit'/>

</form>

    </td>
    <td id='cvright' valign="top">


    </td>
   </tr>
  </tbody>
  </table>
 </div>

 <div id='cvfoot'></div>
</div>

</body>
</html>
